<?php

	$parent_ = mysql_query("SELECT * FROM category WHERE parent is NULL ORDER BY name");
	while($parow = mysql_fetch_array($parent_)){
		if(@$_GET['filter']){
			$filt = mysql_real_escape_string(@$_GET['filter']);
			$filt = strip_tags($filt);
			$sql = "SELECT * FROM category LEFT JOIN cat_fetures ON cat_fetures.cat_id = category.id WHERE category.parent = ".$parow['id']." AND cat_fetures.fet_id = $filt ORDER BY category.name";
			
		}else{
			$sql ="SELECT * FROM category WHERE parent = ".$parow['id'];
		}
		$par_lvl2 = mysql_query($sql);
		
		if(mysql_num_rows($par_lvl2)>0){
?>
		<div class="parentcat_div">
        	
            
            
            
           <table width="100%" border="1">
           
           	<tr>
            	<td class="j-par-title" valign="top">
                	<?php
						echo $parow['name'];		
                	?>
                </td>
                <td style="border-bottom:1px dotted #CCC;">
                	<?php
						$hasfil = 0;
						while($rrow = mysql_fetch_array($par_lvl2)){
							$hasfil++;
					?>
                    <script type="text/javascript">
						function CallItems(id){
							window.location = "items.php?item="+id;
						}
                    </script>
                    <div class="left j-lvl2-title" onclick="CallItems(<?php echo $rrow['id']; ?>)">
                    	<img src="timthumb.php?src=<?php echo curPageURL_folder().str_replace("../../","",$rrow['image']); ?>&w=150&h=150" />
                    	<h3>
						<?php
							echo $rrow['name'];
						?></h3>
                        <span>
                        <?php
							switch($rrow['type']){
								case 'Y':
									echo "Dimmable";
								break;
								case 'N':
									echo "Non-Dimmable";
								break;
								case 'B':
									echo "Dimmable/Non Dimmable";
								break;
							}
						?>
                        </span>
                    </div>	
                    <?php
						}
					?>
                    <div class="clear"></div>
                </td>
            </tr>
           </table>
        </div>
       
<?php
		}
	}
	if(!@$hasfil){
?>
	<div style="padding:20px;">No Data Found</div>
<?php	
	}
?>